<template>
	<view>
		<Header title="模特发布" :showBack="true"></Header>
		<view class="form-box" >
			<com-input label="姓名" v-model="formData.name" required></com-input>
			<com-select label="性别" v-model="formData.sex" :list="sexOptions" required></com-select>
			<com-select label="人员类别"  v-model="formData.type_id" :list="typeOptions" required></com-select>
			<com-input label="年龄" v-model="formData.age" type="number" maxlength="2"></com-input>
			<com-input label="联系电话" v-model="formData.mobile" type="number" maxlength="11" required></com-input>
			<com-select label="地区"  v-model="formData.area" :list="areaOptions" required></com-select>
			<com-select label="国籍" v-model="formData.nationality" :list="countryOptions" required></com-select>
		</view>
		<view class="form-box">
			<com-input label="身高(cm)" v-model="formData.height" type="digit" required></com-input>
			<com-input label="体重(kg)" v-model="formData.weight" type="digit"></com-input>
			<com-input label="三围" v-model="formData.bwh" :list="bwhOptions" mode="multiSelector" :isObject="false" required></com-input>
			<com-input label="鞋码" v-model="formData.ssize" type="number"></com-input>
			<com-input label="服装尺码" v-model="formData.csize" :isObject="false" :list="clothingSizeOptions"></com-input>
		</view>
		<view class="form-box">
			<com-input label="喜好" v-model="formData.like" type="textarea"></com-input>
			<com-input label="技能" v-model="formData.skill" type="textarea"></com-input>
			<com-editbox label="合作品牌" v-model="formData.brand" required></com-editbox>
			<com-input label="备注" v-model="formData.remark" type="textarea"></com-input>
		</view>
		<view class="form-box">
			<com-input label="价格" v-model="formData.price" type="number" required></com-input>
			<com-select label="是否走秀"  v-model="formData.is_show" :list="showOptions" required></com-select>
			<com-select label="单位" v-model="formData.unit" :list="unitOptions"  required></com-select>
			<com-checkbox label="标签" :key="key" v-model="formData.tag" :list="modelTypeOptions" required></com-checkbox>
			<view class="form-item">
				<view class="form-item-label">评分</view>
				<view class="form-item-con score-con">
					<uni-rate class="score" size="16" active-color="#cfb787" :value="formData.score" margin="5" @change="onChange"/>
				</view>
			</view>
		</view>
		<view class="btn-group">
			<button type="primary" @click="saveInfoFn">下一步</button>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	import Header from '@/components/header.vue';
	import comInput from '@/components/com-input/com-input.vue';
	import comSelect from '@/components/com-select/com-select.vue';
	import comCheckbox from '@/components/com-checkbox/com-checkbox.vue';
	import comEditbox from '@/components/com-editbox/com-editbox.vue';
	import {
		SEX,
		COUNTRY,
		MODEL_TYPE,
		AREA,
		HEIGHT,
		WEIGHT,
		BWH,
		SHOESIZE,
		CLOTHINGSIZE,
		PRICE_UNIT
	} from '@/common/dics.js'
	export default {
		components: {
			comInput,
			comSelect,
			comCheckbox,
			comEditbox,
			Header
		},
		data() {
			return {
				sexOptions: SEX,
				countryOptions: COUNTRY,
				modelTypeOptions: [],
				areaOptions: AREA,
				heightOptions: HEIGHT,
				weightOptions: WEIGHT,
				typeOptions: '',
				showOptions: '',
				shoesizeOptions: SHOESIZE,
				bwhOptions: BWH,
				clothingSizeOptions: CLOTHINGSIZE,
				unitOptions: PRICE_UNIT,
				cooperationOptions: [],
				mid: '',
				formData: {
					name: '',
					sex: '',
					age: '',
					mobile: '',
					weight: '',
					area: '',
					type_id: '',
					is_show: '',
					nationality: '',
					height: '',
					tag: [],
					like:'',
					csize: '',
					ssize: '',
					skill: '',
					bwh: '',
					brand: '',
					unit: '',
					score: '',
				},
				key: false
			};
		},
		computed: {
		  ...mapState(['uid', 'uploadUrl'])
		},
		mounted() {
		},
		onLoad(e) {
			if(this.$store.state.uid == ''){
				uni.navigateTo({
					url: '/pages/login/login'
				})
			}else{
				if(e.mid){
					this.mid = e.mid;
					this.getModelsInfo(e.mid)
				}
				this.getOptions()
			}
			
		},
		
		methods: {
			onChange(e) {
			   this.formData.score = e.value;
			},
			// 获取配置信息
			async getModelsInfo (mid) {
		
			  const res  = await this.http.httpRequest('/models/getModelsInfo','post',{mid:mid})
			  if (res.data.code == 1) {
				 this.formData = res.data.data
				 
			  } else {
				  this.$u.toast('配置请求失败')
			  }
			  
			},
			// 获取配置信息
			async getOptions () {
				this.key = false
			  const res  = await this.http.httpRequest('/models/getScreen','post',{})
			  if (res.data.code == 1) {
				 const data = res.data.data
				 this.areaOptions = data.areas
				 this.sexOptions = data.sex
				 this.typeOptions = data.type
				 this.showOptions = data.show
				 this.countryOptions = data.nationality
				 this.modelTypeOptions = data.tag
				 this.key = true
			  } else {
				  this.$u.toast('配置请求失败')
			  }
			  
			},
			// 下一步
			async saveInfoFn () {
				
				if (this.formData.name == '') {
					this.$u.toast('姓名不能为空')
				  return	
				}
				
				if (this.formData.sex !== 0 && this.formData.sex !== 1) {
					this.$u.toast('性别不能为空')
					return
				}
				
				if (this.formData.mobile == '') {
					this.$u.toast('联系电话不能为空')
				   return
				}
				if (!RegExp(/^1[345789]\d{9}$/).test(this.formData.mobile)) {
					this.$u.toast('联系电话错误')
				   return
				}
					
				if (this.formData.area == '') {
					this.$u.toast('地区不能为空')
					return
				}
				
				if (this.formData.nationality == '') {
					this.$u.toast('国籍不能为空')
					return
				}
				g
				if (this.formData.type_id == '') {
					this.$u.toast('人员类别不能为空')
					return
				}
				
				if (this.formData.is_show !== 0 && this.formData.is_show !== 1) {
					this.$u.toast('是否走秀为空')
					return
				}
				
				if (this.formData.height == '') {
					this.$u.toast('身高不能为空')
					return
				}
				if (this.formData.bwh == '') {
					this.$u.toast('三围不能为空')
					return
				}
				if (this.formData.ssize == '') {
					this.$u.toast('鞋码不能为空')
					return
				}
				
				if (this.formData.brand == '') {
					this.$u.toast('合作品牌不能为空')
					return
				}
				if (this.formData.price == '') {
					this.$u.toast('价格不能为空')
					return
				}
				if (this.formData.unit == '') {
					this.$u.toast('单位不能为空')
					return
				}
				if (this.formData.tag == '') {
					this.$u.toast('标签不能为空')
					return
				}
				if(this.mid !==''){
					this.formData.mid = this.mid;
				}
				
				let data = encodeURIComponent(JSON.stringify(this.formData));
				
				const params = {data:data , uid: this.$store.state.uid}
				const res = await this.http.httpRequest('/models/updateModelsStepOne','post', params)
				if (res.data.code == 1) {
					console.log(res)
					uni.navigateTo({
						url: './modelPublicTwo/modelPublicTwo?mid='+res.data.data
					})
					console.log(res)
				} else {
					this.$u.toast('创建失败')
				}
			}
		},
		//校验手机格式
		
		
	
		
	}
</script>

<style lang="scss" scoped>
	.form-box{
		.score-con {
			.score {
				display: inline-block;
			}
		}
	}
</style>
